<?php

class TranslateAction extends fvAction {
    
    function __construct () {
        parent::__construct(fvSite::$Layoult);
    }

    function executeIndex() {
        if (fvRequest::getInstance()->isXmlHttpRequest())
            return self::$FV_NO_LAYOULT;
        else return self::$FV_OK;
    }
    
    function executeEdit() {
        if (fvRequest::getInstance()->isXmlHttpRequest())
            return self::$FV_AJAX_CALL;
        else return self::$FV_OK;
    }
    
    function executeSave() {
        $request = fvRequest::getInstance();
        $param_name = $request->getRequestParameter('param_name');
        if ($param_name){
        	$param_values = $request->getRequestParameter('add');
        	$m = unserialize(file_get_contents(LANGUAGES_FILE));
        	$m["languages"][$param_name] = $param_values; 
        }
        else{
        	$m = $request->getRequestParameter('val');
        }
        file_put_contents(LANGUAGES_FILE, serialize($m));
        fvResponce::getInstance()->setHeader('redirect', fvSite::$fvConfig->get('dir_web_root') . $request->getRequestParameter('module') . "/?".rand());
    }    

    function executeDelete() {
        $request = fvRequest::getInstance();
        $m = unserialize(file_get_contents(LANGUAGES_FILE));
        unset($m["languages"][$request->getRequestParameter('id')]);
        file_put_contents(LANGUAGES_FILE, serialize($m));
        $this->setFlash("Данные успешно удалены", self::$FLASH_SUCCESS);
        fvResponce::getInstance()->setHeader('redirect', fvSite::$fvConfig->get('dir_web_root') . $request->getRequestParameter('module') . "/");
        if (fvRequest::getInstance()->isXmlHttpRequest())
            return self::$FV_NO_LAYOULT;
        else return self::$FV_OK;
    }

    function executeGetparameterslist() {
        if (fvRequest::getInstance()->isXmlHttpRequest())
            return self::$FV_AJAX_CALL;
        else $this->redirect404();
    }
}

?>
